home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_pools.h.z / apr_pools.h
C/C++ Source or Header  |  2002-07-08  |  25KB  |  694 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_POOLS_H
  56. #define APR_POOLS_H
  57.  
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61.  
  62.  
  63. /**
  64.  * @file apr_pools.h
  65.  * @brief APR memory allocation
  66.  *
  67.  * Resource allocation routines...
  68.  *
  69.  * designed so that we don't have to keep track of EVERYTHING so that
  70.  * it can be explicitly freed later (a fundamentally unsound strategy ---
  71.  * particularly in the presence of die()).
  72.  *
  73.  * Instead, we maintain pools, and allocate items (both memory and I/O
  74.  * handlers) from the pools --- currently there are two, one for per
  75.  * transaction info, and one for config info.  When a transaction is over,
  76.  * we can delete everything in the per-transaction apr_pool_t without fear,
  77.  * and without thinking too hard about it either.
  78.  */
  79. /**
  80.  * @defgroup APR_Pool Memory Pool Functions
  81.  * @ingroup APR
  82.  * @{
  83.  */
  84. #include "apr.h"
  85. #include "apr_errno.h"
  86. #include "apr_general.h" /* for APR_STRINGIFY */
  87. #define APR_WANT_MEMFUNC
  88. #include "apr_want.h"
  89.  
  90. /** The fundamental pool type */
  91. typedef struct apr_pool_t apr_pool_t;
  92.  
  93.  
  94. /**
  95.  * Pool accessor functions.
  96.  *
  97.  * These standardized function are used by opaque (APR) data types to return
  98.  * the apr_pool_t that is associated with the data type.
  99.  *
  100.  * APR_POOL_DECLARE_ACCESSOR() is used in a header file to declare the
  101.  * accessor function. A typical usage and result would be:
  102.  *
  103.  *    APR_POOL_DECLARE_ACCESSOR(file);
  104.  * becomes:
  105.  *    APR_DECLARE(apr_pool_t *) apr_file_pool_get(apr_file_t *ob);
  106.  *
  107.  * In the implementation, the APR_POOL_IMPLEMENT_ACCESSOR() is used to
  108.  * actually define the function. It assumes the field is named "pool".
  109.  *
  110.  * Note: the linkage is specified for APR. It would be possible to expand
  111.  *       the macros to support other linkages.
  112.  */
  113.  
  114. #define APR_POOL_DECLARE_ACCESSOR(typename) \
  115.     APR_DECLARE(apr_pool_t *) apr_##typename##_pool_get \
  116.         (const apr_##typename##_t *ob)
  117.  
  118. /** used to implement the pool accessor */
  119. #define APR_POOL_IMPLEMENT_ACCESSOR(typename) \
  120.     APR_DECLARE(apr_pool_t *) apr_##typename##_pool_get \
  121.         (const apr_##typename##_t *ob) { return ob->pool; }
  122.  
  123.  
  124.  
  125. /**
  126.  * Pool debug levels
  127.  *
  128.  * <pre>
  129.  * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  130.  * ---------------------------------
  131.  * |   |   |   |   |   |   |   | x |  General debug code enabled (usefull in
  132.  *                                    combination with --with-efence).
  133.  *
  134.  * |   |   |   |   |   |   | x |   |  Verbose output on stderr (report
  135.  *                                    CREATE, CLEAR, DESTROY).
  136.  *
  137.  * |   |   |   | x |   |   |   |   |  Verbose output on stderr (report
  138.  *                                    PALLOC, PCALLOC).
  139.  *
  140.  * |   |   |   |   |   | x |   |   |  Lifetime checking. On each use of a
  141.  *                                    pool, check its lifetime.  If the pool
  142.  *                                    is out of scope, abort().
  143.  *                                    In combination with the verbose flag
  144.  *                                    above, it will output LIFE in such an
  145.  *                                    event prior to aborting.
  146.  *
  147.  * |   |   |   |   | x |   |   |   |  Pool owner checking.  On each use of a
  148.  *                                    pool, check if the current thread is the
  149.  *                                    pools owner.  If not, abort().  In
  150.  *                                    combination with the verbose flag above,
  151.  *                                    it will output OWNER in such an event
  152.  *                                    prior to aborting.  Use the debug
  153.  *                                    function apr_pool_owner_set() to switch
  154.  *                                    a pools ownership.
  155.  *
  156.  * When no debug level was specified, assume general debug mode.
  157.  * If level 0 was specified, debugging is switched off
  158.  * </pre>
  159.  */
  160. #if defined(APR_POOL_DEBUG)
  161. #if (APR_POOL_DEBUG != 0) && (APR_POOL_DEBUG - 0 == 0)
  162. #undef APR_POOL_DEBUG
  163. #define APR_POOL_DEBUG 1
  164. #endif
  165. #else
  166. #define APR_POOL_DEBUG 0
  167. #endif
  168.  
  169. /** the place in the code where the particular function was called */
  170. #define APR_POOL__FILE_LINE__ __FILE__ ":" APR_STRINGIFY(__LINE__)
  171.  
  172.  
  173.  
  174. /** A function that is called when allocation fails. */
  175. typedef int (*apr_abortfunc_t)(int retcode);
  176.  
  177. /*
  178.  * APR memory structure manipulators (pools, tables, and arrays).
  179.  */
  180.  
  181. /*
  182.  * Initialization
  183.  */
  184.  
  185. /**
  186.  * Setup all of the internal structures required to use pools
  187.  * @remark Programs do NOT need to call this directly.  APR will call this
  188.  *      automatically from apr_initialize.
  189.  * @internal
  190.  */
  191. APR_DECLARE(apr_status_t) apr_pool_initialize(void);
  192.  
  193. /**
  194.  * Tear down all of the internal structures required to use pools
  195.  * @remark Programs do NOT need to call this directly.  APR will call this
  196.  *      automatically from apr_terminate.
  197.  * @internal
  198.  */
  199. APR_DECLARE(void) apr_pool_terminate(void);
  200.  
  201.  
  202. /*
  203.  * Pool creation/destruction
  204.  */
  205.  
  206. #include "apr_allocator.h"
  207.  
  208. /**
  209.  * Create a new pool.
  210.  * @param newpool The pool we have just created.
  211.  * @param parent The parent pool.  If this is NULL, the new pool is a root
  212.  *        pool.  If it is non-NULL, the new pool will inherit all
  213.  *        of its parent pool's attributes, except the apr_pool_t will
  214.  *        be a sub-pool.
  215.  * @param apr_abort A function to use if the pool cannot allocate more memory.
  216.  * @param allocator The allocator to use with the new pool.  If NULL the
  217.  *        allocator of the parent pool will be used.
  218.  */
  219. APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
  220.                                              apr_pool_t *parent,
  221.                                              apr_abortfunc_t abort_fn,
  222.                                              apr_allocator_t *allocator);
  223.  
  224. /**
  225.  * Debug version of apr_pool_create_ex.
  226.  * @param newpool @see apr_pool_create.
  227.  * @param parent @see apr_pool_create.
  228.  * @param abort_fn @see apr_pool_create.
  229.  * @param allocator @see apr_pool_create.
  230.  * @param file_line Where the function is called from.
  231.  *        This is usually APR_POOL__FILE_LINE__.
  232.  * @remark Only available when APR_POOL_DEBUG is defined.
  233.  *         Call this directly if you have you apr_pool_create_ex
  234.  *         calls in a wrapper function and wish to override
  235.  *         the file_line argument to reflect the caller of
  236.  *         your wrapper function.  If you do not have
  237.  *         apr_pool_create_ex in a wrapper, trust the macro
  238.  *         and don't call apr_pool_create_ex_debug directly.
  239.  */
  240. APR_DECLARE(apr_status_t) apr_pool_create_ex_debug(apr_pool_t **newpool,
  241.                                                    apr_pool_t *parent,
  242.                                                    apr_abortfunc_t abort_fn,
  243.                                                    apr_allocator_t *allocator,
  244.                                                    const char *file_line);
  245.  
  246. #if APR_POOL_DEBUG
  247. #define apr_pool_create_ex(newpool, parent, abort_fn, allocator)  \
  248.     apr_pool_create_ex_debug(newpool, parent, abort_fn, allocator, \
  249.                              APR_POOL__FILE_LINE__)
  250. #endif
  251.  
  252. /**
  253.  * Create a new pool.
  254.  * @param newpool The pool we have just created.
  255.  * @param parent The parent pool.  If this is NULL, the new pool is a root
  256.  *        pool.  If it is non-NULL, the new pool will inherit all
  257.  *        of its parent pool's attributes, except the apr_pool_t will
  258.  *        be a sub-pool.
  259.  */
  260. #if defined(DOXYGEN)
  261. APR_DECLARE(apr_status_t) apr_pool_create(apr_pool_t **newpool,
  262.                                           apr_pool_t *parent);
  263. #else
  264. #if APR_POOL_DEBUG
  265. #define apr_pool_create(newpool, parent) \
  266.     apr_pool_create_ex_debug(newpool, parent, NULL, NULL, \
  267.                              APR_POOL__FILE_LINE__)
  268. #else
  269. #define apr_pool_create(newpool, parent) \
  270.     apr_pool_create_ex(newpool, parent, NULL, NULL)
  271. #endif
  272. #endif
  273.  
  274. /** @deprecated @see apr_pool_create_ex */
  275. #if APR_POOL_DEBUG
  276. #define apr_pool_sub_make(newpool, parent, abort_fn) \
  277.     (void)apr_pool_create_ex_debug(newpool, parent, abort_fn, \
  278.                                    NULL, \
  279.                                    APR_POOL__FILE_LINE__)
  280. #else
  281. #define apr_pool_sub_make(newpool, parent, abort_fn) \
  282.     (void)apr_pool_create_ex(newpool, parent, abort_fn, NULL)
  283. #endif
  284.  
  285. /**
  286.  * Find the pools allocator
  287.  * @param pool The pool to get the allocator from.
  288.  */
  289. APR_DECLARE(apr_allocator_t *) apr_pool_allocator_get(apr_pool_t *pool);
  290.  
  291. /**
  292.  * Clear all memory in the pool and run all the cleanups. This also destroys all
  293.  * subpools.
  294.  * @param p The pool to clear
  295.  * @remark This does not actually free the memory, it just allows the pool
  296.  *         to re-use this memory for the next allocation.
  297.  * @see apr_pool_destroy()
  298.  */
  299. APR_DECLARE(void) apr_pool_clear(apr_pool_t *p);
  300.  
  301. /**
  302.  * Debug version of apr_pool_clear.
  303.  * @param p See: apr_pool_clear.
  304.  * @param file_line Where the function is called from.
  305.  *        This is usually APR_POOL__FILE_LINE__.
  306.  * @remark Only available when APR_POOL_DEBUG is defined.
  307.  *         Call this directly if you have you apr_pool_clear
  308.  *         calls in a wrapper function and wish to override
  309.  *         the file_line argument to reflect the caller of
  310.  *         your wrapper function.  If you do not have
  311.  *         apr_pool_clear in a wrapper, trust the macro
  312.  *         and don't call apr_pool_destroy_clear directly.
  313.  */
  314. APR_DECLARE(void) apr_pool_clear_debug(apr_pool_t *p,
  315.                                        const char *file_line);
  316.  
  317. #if APR_POOL_DEBUG
  318. #define apr_pool_clear(p) \
  319.     apr_pool_clear_debug(p, APR_POOL__FILE_LINE__)
  320. #endif
  321.  
  322. /**
  323.  * Destroy the pool. This takes similar action as apr_pool_clear() and then
  324.  * frees all the memory.
  325.  * @param p The pool to destroy
  326.  * @remark This will actually free the memory
  327.  */
  328. APR_DECLARE(void) apr_pool_destroy(apr_pool_t *p);
  329.  
  330. /**
  331.  * Debug version of apr_pool_destroy.
  332.  * @param p See: apr_pool_destroy.
  333.  * @param file_line Where the function is called from.
  334.  *        This is usually APR_POOL__FILE_LINE__.
  335.  * @remark Only available when APR_POOL_DEBUG is defined.
  336.  *         Call this directly if you have you apr_pool_destroy
  337.  *         calls in a wrapper function and wish to override
  338.  *         the file_line argument to reflect the caller of
  339.  *         your wrapper function.  If you do not have
  340.  *         apr_pool_destroy in a wrapper, trust the macro
  341.  *         and don't call apr_pool_destroy_debug directly.
  342.  */
  343. APR_DECLARE(void) apr_pool_destroy_debug(apr_pool_t *p,
  344.                                          const char *file_line);
  345.  
  346. #if APR_POOL_DEBUG
  347. #define apr_pool_destroy(p) \
  348.     apr_pool_destroy_debug(p, APR_POOL__FILE_LINE__)
  349. #endif
  350.  
  351.  
  352. /*
  353.  * Memory allocation
  354.  */
  355.  
  356. /**
  357.  * Allocate a block of memory from a pool
  358.  * @param p The pool to allocate from
  359.  * @param size The amount of memory to allocate
  360.  * @return The allocated memory
  361.  */
  362. APR_DECLARE(void *) apr_palloc(apr_pool_t *p, apr_size_t size);
  363.  
  364. /**
  365.  * Debug version of apr_palloc
  366.  * @param p See: apr_palloc
  367.  * @param size See: apr_palloc
  368.  * @param file_line Where the function is called from.
  369.  *        This is usually APR_POOL__FILE_LINE__.
  370.  * @return See: apr_palloc
  371.  */
  372. APR_DECLARE(void *) apr_palloc_debug(apr_pool_t *p, apr_size_t size,
  373.                                      const char *file_line);
  374.  
  375. #if APR_POOL_DEBUG
  376. #define apr_palloc(p, size) \
  377.     apr_palloc_debug(p, size, APR_POOL__FILE_LINE__)
  378. #endif
  379.  
  380. /**
  381.  * Allocate a block of memory from a pool and set all of the memory to 0
  382.  * @param p The pool to allocate from
  383.  * @param size The amount of memory to allocate
  384.  * @return The allocated memory
  385.  */
  386. #if defined(DOXYGEN)
  387. APR_DECLARE(void *) apr_pcalloc(apr_pool_t *p, apr_size_t size);
  388. #elif !APR_POOL_DEBUG
  389. #define apr_pcalloc(p, size) memset(apr_palloc(p, size), 0, size)
  390. #endif
  391.  
  392. /**
  393.  * Debug version of apr_pcalloc
  394.  * @param p See: apr_pcalloc
  395.  * @param size See: apr_pcalloc
  396.  * @param file_line Where the function is called from.
  397.  *        This is usually APR_POOL__FILE_LINE__.
  398.  * @return See: apr_pcalloc
  399.  */
  400. APR_DECLARE(void *) apr_pcalloc_debug(apr_pool_t *p, apr_size_t size,
  401.                                       const char *file_line);
  402.  
  403. #if APR_POOL_DEBUG
  404. #define apr_pcalloc(p, size) \
  405.     apr_pcalloc_debug(p, size, APR_POOL__FILE_LINE__)
  406. #endif
  407.  
  408.  
  409. /*
  410.  * Pool Properties
  411.  */
  412.  
  413. /**
  414.  * Set the function to be called when an allocation failure occurs.
  415.  * @tip If the program wants APR to exit on a memory allocation error,
  416.  *      then this function can be called to set the callback to use (for
  417.  *      performing cleanup and then exiting). If this function is not called,
  418.  *      then APR will return an error and expect the calling program to
  419.  *      deal with the error accordingly.
  420.  */
  421. APR_DECLARE(void) apr_pool_abort_set(apr_abortfunc_t abortfunc,
  422.                                      apr_pool_t *pool);
  423.  
  424. /** @deprecated @see apr_pool_abort_set */
  425. APR_DECLARE(void) apr_pool_set_abort(apr_abortfunc_t abortfunc,
  426.                                      apr_pool_t *pool);
  427.  
  428. /**
  429.  * Get the abort function associated with the specified pool.
  430.  * @param pool The pool for retrieving the abort function.
  431.  * @return The abort function for the given pool.
  432.  */
  433. APR_DECLARE(apr_abortfunc_t) apr_pool_abort_get(apr_pool_t *pool);
  434.  
  435. /** @deprecated @see apr_pool_abort_get */
  436. APR_DECLARE(apr_abortfunc_t) apr_pool_get_abort(apr_pool_t *pool);
  437.  
  438. /**
  439.  * Get the parent pool of the specified pool.
  440.  * @param pool The pool for retrieving the parent pool.
  441.  * @return The parent of the given pool.
  442.  */
  443. APR_DECLARE(apr_pool_t *) apr_pool_parent_get(apr_pool_t *pool);
  444.  
  445. /** @deprecated @see apr_pool_parent_get */
  446. APR_DECLARE(apr_pool_t *) apr_pool_get_parent(apr_pool_t *pool);
  447.  
  448. /**
  449.  * Determine if pool a is an ancestor of pool b
  450.  * @param a The pool to search
  451.  * @param b The pool to search for
  452.  * @return True if a is an ancestor of b, NULL is considered an ancestor
  453.  *         of all pools.
  454.  */
  455. APR_DECLARE(int) apr_pool_is_ancestor(apr_pool_t *a, apr_pool_t *b);
  456.  
  457. /**
  458.  * Tag a pool (give it a name)
  459.  * @param pool The pool to tag
  460.  * @param tag  The tag
  461.  */
  462. APR_DECLARE(void) apr_pool_tag(apr_pool_t *pool, const char *tag);
  463.  
  464.  
  465. /*
  466.  * User data management
  467.  */
  468.  
  469. /**
  470.  * Set the data associated with the current pool
  471.  * @param data The user data associated with the pool.
  472.  * @param key The key to use for association
  473.  * @param cleanup The cleanup program to use to cleanup the data (NULL if none)
  474.  * @param pool The current pool
  475.  * @warning The data to be attached to the pool should have a life span
  476.  *          at least as long as the pool it is being attached to.
  477.  *
  478.  *      Users of APR must take EXTREME care when choosing a key to
  479.  *      use for their data.  It is possible to accidentally overwrite
  480.  *      data by choosing a key that another part of the program is using
  481.  *      It is advised that steps are taken to ensure that a unique
  482.  *      key is used at all times.
  483.  * @bug Specify how to ensure this uniqueness!
  484.  */
  485. APR_DECLARE(apr_status_t) apr_pool_userdata_set(
  486.     const void *data,
  487.     const char *key,
  488.     apr_status_t (*cleanup)(void *),
  489.     apr_pool_t *pool);
  490.  
  491. /**
  492.  * Set the data associated with the current pool
  493.  * @param data The user data associated with the pool.
  494.  * @param key The key to use for association
  495.  * @param cleanup The cleanup program to use to cleanup the data (NULL if none)
  496.  * @param pool The current pool
  497.  * @note same as apr_pool_userdata_set(), except that this version doesn't
  498.  *       make a copy of the key (this function is useful, for example, when
  499.  *       the key is a string literal)
  500.  * @warning This should NOT be used if the key could change addresses by
  501.  *       any means between the apr_pool_userdata_setn() call and a
  502.  *       subsequent apr_pool_userdata_get() on that key, such as if a
  503.  *       static string is used as a userdata key in a DSO and the DSO could
  504.  *       be unloaded and reloaded between the _setn() and the _get().  You
  505.  *       MUST use apr_pool_userdata_set() in such cases.
  506.  * @warning More generally, the key and the data to be attached to the
  507.  *       pool should have a life span at least as long as the pool itself.
  508.  *
  509.  */
  510. APR_DECLARE(apr_status_t) apr_pool_userdata_setn(
  511.     const void *data,
  512.     const char *key,
  513.     apr_status_t (*cleanup)(void *),
  514.     apr_pool_t *pool);
  515.  
  516. /**
  517.  * Return the data associated with the current pool.
  518.  * @param data The user data associated with the pool.
  519.  * @param key The key for the data to retrieve
  520.  * @param pool The current pool.
  521.  */
  522. APR_DECLARE(apr_status_t) apr_pool_userdata_get(void **data, const char *key,
  523.                                                 apr_pool_t *pool);
  524.  
  525.  
  526. /*
  527.  * Cleanup
  528.  */
  529.  
  530. /**
  531.  * Register a function to be called when a pool is cleared or destroyed
  532.  * @param p The pool register the cleanup with
  533.  * @param data The data to pass to the cleanup function.
  534.  * @param plain_cleanup The function to call when the pool is cleared
  535.  *                      or destroyed
  536.  * @param child_cleanup The function to call when a child process is being
  537.  *                      shutdown - this function is called in the child, obviously!
  538.  */
  539. APR_DECLARE(void) apr_pool_cleanup_register(
  540.     apr_pool_t *p,
  541.     const void *data,
  542.     apr_status_t (*plain_cleanup)(void *),
  543.     apr_status_t (*child_cleanup)(void *));
  544.  
  545. /**
  546.  * Remove a previously registered cleanup function
  547.  * @param p The pool remove the cleanup from
  548.  * @param data The data to remove from cleanup
  549.  * @param cleanup The function to remove from cleanup
  550.  * @remarks For some strange reason only the plain_cleanup is handled by this
  551.  *          function
  552.  */
  553. APR_DECLARE(void) apr_pool_cleanup_kill(apr_pool_t *p, const void *data,
  554.                                         apr_status_t (*cleanup)(void *));
  555.  
  556. /**
  557.  * Replace the child cleanup of a previously registered cleanup
  558.  * @param p The pool of the registered cleanup
  559.  * @param data The data of the registered cleanup
  560.  * @param plain_cleanup The plain cleanup function of the registered cleanup
  561.  * @param child_cleanup The function to register as the child cleanup
  562.  */
  563. APR_DECLARE(void) apr_pool_child_cleanup_set(
  564.     apr_pool_t *p,
  565.     const void *data,
  566.     apr_status_t (*plain_cleanup)(void *),
  567.     apr_status_t (*child_cleanup)(void *));
  568.  
  569. /**
  570.  * Run the specified cleanup function immediately and unregister it. Use
  571.  * @a data instead of the data that was registered with the cleanup.
  572.  * @param p The pool remove the cleanup from
  573.  * @param data The data to remove from cleanup
  574.  * @param cleanup The function to remove from cleanup
  575.  */
  576. APR_DECLARE(apr_status_t) apr_pool_cleanup_run(
  577.     apr_pool_t *p,
  578.     void *data,
  579.     apr_status_t (*cleanup)(void *));
  580.  
  581. /**
  582.  * An empty cleanup function
  583.  * @param data The data to cleanup
  584.  */
  585. APR_DECLARE_NONSTD(apr_status_t) apr_pool_cleanup_null(void *data);
  586.  
  587. /* Preparing for exec() --- close files, etc., but *don't* flush I/O
  588.  * buffers, *don't* wait for subprocesses, and *don't* free any memory.
  589.  */
  590. /**
  591.  * Run all of the child_cleanups, so that any unnecessary files are
  592.  * closed because we are about to exec a new program
  593.  */
  594. APR_DECLARE(void) apr_pool_cleanup_for_exec(void);
  595.  
  596.  
  597. /**
  598.  * @defgroup PoolDebug Pool Debugging functions.
  599.  *
  600.  * pools have nested lifetimes -- sub_pools are destroyed when the
  601.  * parent pool is cleared.  We allow certain liberties with operations
  602.  * on things such as tables (and on other structures in a more general
  603.  * sense) where we allow the caller to insert values into a table which
  604.  * were not allocated from the table's pool.  The table's data will
  605.  * remain valid as long as all the pools from which its values are
  606.  * allocated remain valid.
  607.  *
  608.  * For example, if B is a sub pool of A, and you build a table T in
  609.  * pool B, then it's safe to insert data allocated in A or B into T
  610.  * (because B lives at most as long as A does, and T is destroyed when
  611.  * B is cleared/destroyed).  On the other hand, if S is a table in
  612.  * pool A, it is safe to insert data allocated in A into S, but it
  613.  * is *not safe* to insert data allocated from B into S... because
  614.  * B can be cleared/destroyed before A is (which would leave dangling
  615.  * pointers in T's data structures).
  616.  *
  617.  * In general we say that it is safe to insert data into a table T
  618.  * if the data is allocated in any ancestor of T's pool.  This is the
  619.  * basis on which the APR_POOL_DEBUG code works -- it tests these ancestor
  620.  * relationships for all data inserted into tables.  APR_POOL_DEBUG also
  621.  * provides tools (apr_pool_find, and apr_pool_is_ancestor) for other
  622.  * folks to implement similar restrictions for their own data
  623.  * structures.
  624.  *
  625.  * However, sometimes this ancestor requirement is inconvenient --
  626.  * sometimes we're forced to create a sub pool (such as through
  627.  * apr_sub_req_lookup_uri), and the sub pool is guaranteed to have
  628.  * the same lifetime as the parent pool.  This is a guarantee implemented
  629.  * by the *caller*, not by the pool code.  That is, the caller guarantees
  630.  * they won't destroy the sub pool individually prior to destroying the
  631.  * parent pool.
  632.  *
  633.  * In this case the caller must call apr_pool_join() to indicate this
  634.  * guarantee to the APR_POOL_DEBUG code.  There are a few examples spread
  635.  * through the standard modules.
  636.  *
  637.  * These functions are only implemented when #APR_POOL_DEBUG is set.
  638.  *
  639.  * @{
  640.  */
  641. #if APR_POOL_DEBUG || defined(DOXYGEN)
  642. /**
  643.  * Guarantee that a subpool has the same lifetime as the parent.
  644.  * @param p The parent pool
  645.  * @param sub The subpool
  646.  */
  647. APR_DECLARE(void) apr_pool_join(apr_pool_t *p, apr_pool_t *sub);
  648.  
  649. /**
  650.  * Find a pool from something allocated in it.
  651.  * @param mem The thing allocated in the pool
  652.  * @return The pool it is allocated in
  653.  */
  654. APR_DECLARE(apr_pool_t *) apr_pool_find(const void *mem);
  655.  
  656. /**
  657.  * Report the number of bytes currently in the pool
  658.  * @param p The pool to inspect
  659.  * @param recurse Recurse/include the subpools' sizes
  660.  * @return The number of bytes
  661.  */
  662. APR_DECLARE(apr_size_t) apr_pool_num_bytes(apr_pool_t *p, int recurse);
  663.  
  664. /**
  665.  * Lock a pool
  666.  * @param pool The pool to lock
  667.  * @param flag  The flag
  668.  */
  669. APR_DECLARE(void) apr_pool_lock(apr_pool_t *pool, int flag);
  670.  
  671. /* @} */
  672.  
  673. #else /* APR_POOL_DEBUG or DOXYGEN */
  674.  
  675. #ifdef apr_pool_join
  676. #undef apr_pool_join
  677. #endif
  678. #define apr_pool_join(a,b)
  679.  
  680. #ifdef apr_pool_lock
  681. #undef apr_pool_lock
  682. #endif
  683. #define apr_pool_lock(pool, lock)
  684.  
  685. #endif /* APR_POOL_DEBUG or DOXYGEN */
  686.  
  687.  
  688. /** @} */
  689. #ifdef __cplusplus
  690. }
  691. #endif
  692.  
  693. #endif /* !APR_POOLS_H */
  694.